package top.wshape1.shiziapi.message.config;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import top.wshape1.shiziapi.message.websocket.MyHandshakeInterceptor;
import top.wshape1.shiziapi.message.websocket.MyWebSocketHandler;

@Configuration
@EnableWebSocket
@Slf4j
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private MyWebSocketHandler webSocketHandler;

    @Resource
    private MyHandshakeInterceptor handshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry
                .addHandler(webSocketHandler, "/websocket")
                .addInterceptors(handshakeInterceptor)
                .setAllowedOriginPatterns("*");
    }
}